/**
 * Created by yananliu on 2017/12/18.
 */

import * as React from 'react';
import {GalleryVO} from "../vo/GalleryVO";
import AjaxUtil from "../util/AjaxUtil";
import {getGalleryList} from "../constant/apis";
import {ResponseBean} from "../bean/ResponseBean";
import {JSONUtil} from "../util/JSONUtil";

declare const Swiper : any;

interface State {
    gallery : Function
    galleryList : Array<GalleryVO>
}

class GalleryComponent extends React.Component{

    public state : State = {
        gallery : null,
        galleryList : []
    };


    componentDidMount(){

        const that = this;
        
        AjaxUtil.sendRequest(getGalleryList,{},function (data:any) {

            const res : ResponseBean = JSONUtil.JSONToClass(new ResponseBean(),data);

            that.setState({galleryList:res.shujuliebiaodemingzi},function () {

                this.state.gallery = new Swiper('.swiper-container', {autoplay: 5000});

            })

        });

    }


    componentDidUpdate(nextProps:Object){


    }

    render(){

        return <div className="ig">
            <div className="swiper-container">
                <div className="swiper-wrapper">
                    {
                        this.state.galleryList.map(function (value,index) {
                            return <div className="swiper-slide" key={index}>
                                <img src={value.url} />

                            </div>
                        })
                    }
                </div>
            </div>
        </div>

    }

}

export default GalleryComponent;